//
//  SubscriptionTableViewController.m
//  ksjv2
//
//  Created by mac on 14/12/23.
//  Copyright (c) 2014年 CnbizMedia. All rights reserved.
//

#import "SubscriptionTableViewController.h"
#import "Util.h"
#import "DPMeterView.h"
#import "SubscriptionCell.h"
#import "UIBezierPath+BasicShapes.h"
#import "LoginViewController.h"
#import "OrderViewController.h"
#import "Masonry.h"
#import "RecipeCollectionHeaderView.h"
#import "RecipeCollectionFooterView.h"
#import "AGoodsViewController.h"

@interface SubscriptionTableViewController ()<EGORefreshTableHeaderDelegate,UIScrollViewDelegate,UIAlertViewDelegate,UICollectionViewDelegateFlowLayout>{
    PageControlScrollView*Pscroll;//头图
    
    NSMutableArray*ArraySubTable;
    NSMutableArray*ArrayMeTableView;
    NSString*magid;

//    NSMutableArray*productArray;
//    SubscriptionCell *buyCell;
    NSDictionary *magData ;
    
    int _page;//页码
    
    NSMutableArray *_userData;//所有数据
    NSMutableArray* topArray;//头图数据
    BOOL isLoading;//是否在刷新
    //    NSString*slugKey;
    //    NSString*downlad_URL;
    BOOL reloading;//
    
    
    __weak IBOutlet UICollectionView *myCollectionView;
    
    float acc;
}
@property (strong, nonatomic) UISegmentedControl *segmented;
@property (weak, nonatomic) IBOutlet UIView *HeadView;
@property (weak, nonatomic) IBOutlet UITableView *subTableView;//推荐tableview
@property (weak, nonatomic) IBOutlet UITableView *meTableView;//我的订阅tableview
@property (weak, nonatomic) IBOutlet UITableView *mallTableview;


@property(nonatomic,strong)EGORefreshTableHeaderView * refreshHeaderView;
@property(nonatomic,assign)BOOL reloading;
@property(nonatomic,strong)EGORefreshTableHeaderView * refreshHeaderViewTo;
@property(nonatomic,assign)BOOL reloadingTo;
@end

@implementation SubscriptionTableViewController
@synthesize refreshHeaderView=_refreshHeaderView;
@synthesize reloading=_reloading;
@synthesize refreshHeaderViewTo=_refreshHeaderViewTo;
@synthesize reloadingTo=_reloadingTo;
//@synthesize refreshHeaderViewTo=_refreshHeaderViewThr;
//@synthesize reloadingTo=_reloadingThr;

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [UserDefaults setObject:@"right" forKey:@"center"];
    self.hidesBottomBarWhenPushed = NO;
    
    NSLog(@"商城正在刷新");
}

- (void)viewDidDisappear:(BOOL)animated{
    [UserDefaults setObject:@"center" forKey:@"center"];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"订购";
    
    [UserDefaults setObject:@"right" forKey:@"center"];
    
    _page = 1;
    _userData=[[NSMutableArray alloc]init];
    topArray=[[NSMutableArray alloc]init];
    
    UIImageView *headBackImage = [[UIImageView alloc]init];
    
    
    NSString *iphoneTheHight = [UserDefaults objectForKey:@"iphoneTheHight"];
    if ([iphoneTheHight isEqualToString:@"iphone5"]) {
        [headBackImage sd_setImageWithURL:[UserDefaults objectForKey:@"headBack_NewYear5"] ];
        
    }
    if ([iphoneTheHight isEqualToString:@"iphone6"]) {
        [headBackImage sd_setImageWithURL:[UserDefaults objectForKey:@"headBack_NewYear6"] ];
    }
    if ([iphoneTheHight isEqualToString:@"iphone6p"]) {
        [headBackImage sd_setImageWithURL:[UserDefaults objectForKey:@"headBack_NewYear6p"] ];
    }
    
//    [self.navigationController.navigationBar setBackgroundImage:headBackImage.image forBarMetrics:UIBarMetricsDefault];
    
    
    
    
    //判断是不是要放置新春版
    NSString *newOldYear = [UserDefaults objectForKey:@"NewYear" ];
    if ([newOldYear isEqualToString:@"NewYear"]) {
 
        
        NSString *iphoneTheHight = [UserDefaults objectForKey:@"iphoneTheHight"];
        if ([iphoneTheHight isEqualToString:@"iphone5"]) {
            [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"headBack_NewYear5"] forBarMetrics:UIBarMetricsDefault];
        }
        if ([iphoneTheHight isEqualToString:@"iphone6"]) {
            [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"headBack_NewYear6"] forBarMetrics:UIBarMetricsDefault];
        }
        if ([iphoneTheHight isEqualToString:@"iphone6p"]) {
            [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"headBack_NewYear6p"] forBarMetrics:UIBarMetricsDefault];
        }
        
        [self.navigationController.navigationBar setTitleTextAttributes:
         
         @{NSFontAttributeName:[UIFont systemFontOfSize:17],
           
           NSForegroundColorAttributeName:[UIColor whiteColor]}];
    }
    
    [_tuiJianButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [_myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

   
    
    
    [SVProgressHUD show];
    [ self mallTableLoadNews];
    [self initTable];
    [self doneLoadingViewData];
    
    
    
    myCollectionView.hidden = YES;
//    [self subTableloadNews];

}


//-(void)viewWillAppear:(BOOL)animated{
//    
////    [self doneLoadingViewData];
//}


-(void)viewWillDisappear:(BOOL)animated{
    
}

//商城获取数据
-(void)mallTableLoadNews{
    [SVProgressHUD show];
    
    NSMutableDictionary*parameter;
    if (_page==1) {
        parameter=[@{@"p":[NSString stringWithFormat:@"%d",_page],@"top":@"1"} mutableCopy];
    }else{
        parameter=[@{@"p":[NSString stringWithFormat:@"%d",_page]} mutableCopy];
    }
    
    
    
        
        [[AppAPIClient sharedClient] GET:@"Shop/List" parameters:parameter success:^(AFHTTPRequestOperation *operation, id responseObject) {
            
            NSMutableDictionary *result = responseObject[@"data"];
            
            NSLog(@"result -=-= %@",result);
            NSLog(@"parameter mall shop %@",parameter);
            NSLog(@"operation mall shop %@",operation);
  
            if([result isKindOfClass:[NSNull class]] || [result count] == 0||[result[@"content"] count]==0){
                [SVProgressHUD dismiss];
//                [self.mallTableview reloadData];
//                [self.refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.mallTableview];
 
                return;
            }
            
            if(_userData.count==0){
                
                _userData = [[NSMutableArray alloc]initWithArray:result[@"content"] copyItems:YES];
                
//                NSMutableArray *subArray1 = [[NSMutableArray alloc]initWithArray:result[@"content"] copyItems:YES];
//                NSMutableArray *subArray2 = [[NSMutableArray alloc]initWithArray:result[@"content"] copyItems:YES];
//                
//                _userData = [NSMutableArray arrayWithArray:subArray2];
//                [_userData insertObject:@"" atIndex:0];

                
            }
            
            else{
                
                [_userData addObjectsFromArray:result[@"content"]];
                
//                NSMutableArray *subArray1 = [[NSMutableArray alloc]initWithArray:result[@"content"] copyItems:YES];
//                NSMutableArray *subArray2 = [[NSMutableArray alloc]initWithArray:result[@"content"] copyItems:YES];
//           
//                [_userData addObjectsFromArray:subArray2];
            }
            
                
            _page++;
            NSLog(@"_page++ %d",_page);
            if (topArray.count==0) {
                topArray=[[NSMutableArray alloc]initWithArray:responseObject[@"data"][@"top"] copyItems:YES];
                NSMutableArray*array=[[NSMutableArray alloc]init];
                
                
                [UserDefaults setObject:topArray forKey:@"goodsTopArray"];
                
                
                ///滚动头图
    
                for (NSDictionary*dic in topArray) {
                    PageImageView*view=[[PageImageView alloc]init];
                    view.All_Dic=dic;
                    view.ID=dic[@"id"];
                    view.PCatid=dic[@"catid"];
                    view.imageUrl=dic[@"pic"][0];
                    view.PTitle=dic[@"title"];
                    view.URL=dic[@"url"];
                    //                [array addObject:view];
                    //                [array insertObject:view atIndex:0];
                    [array addObject:view];
                     
                }
                
//                [Pscroll refresh:array];
                float h = 165;
                if (self.view.frame.size.width>320) {
                    h+=45;
                }
                
                Pscroll = [[PageControlScrollView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, h) pictures:array whichView:@"mall"];//字符串是用来区分不同页面的滚动头图的区别的，显示效果不同.这里有时间要进行更换
                Pscroll.delegate = self;
            }
            
            
            //         [_userData insertObject:@"" atIndex:0];
            
            [SVProgressHUD dismiss];
            isLoading = NO;
            reloading = NO;
            [self.refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.mallTableview];
            
            //        for (NSDictionary *abc in cityArray) {
            //            //                [@"catdir"]
            //            if ([_slug isEqualToString:abc[@"catdir"]]  ) {
            ////                self.tableView =
            //                theTableView = [UserDefaults objectForKey:@"theTableView"];//从单例中取出来
            //                NSLog(@"thechange theTableView %@",theTableView);
            ////                [theTableView reloadData];
            //                [self.tableView reloadData];
            //                return;
            //            }
            //            
            //            
            //        }
            
            NSLog(@"_userData (=-+_) %@",_userData);
//            [self.mallTableview reloadData];
            [myCollectionView reloadData];
            
            myCollectionView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1];
            myCollectionView.hidden = YES;

            
            [self.refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:myCollectionView];
            NSLog(@"加载完成");
        } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
            NSLog(@"ERR: %@",operation.responseString);
            isLoading = NO;
            reloading = NO;
            [SVProgressHUD showErrorWithStatus:@"网络错误"];
            [self.refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:myCollectionView];
        }];

    
    
//    [myCollectionView registerClass:[MyHeadView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"hxwHeader"];

    
    acc = (self.view.frame.size.width - 1) / 2 ;
    
    NSLog(@"ACC %f",acc);

}

-(void)subTableloadNews{
    [SVProgressHUD show];
    if (!IFUserLogin) {
        [[AppAPIClient sharedClient]setTokenA:@""];
    }else{
        [[AppAPIClient sharedClient]setTokenA:[UserDefaults objectForKey:@"token"]];
    }
    
    
    NSString *openUdid = [OpenUDID_UDID value];
    NSLog(@"openUdid == %@",openUdid);

    [[AppAPIClient sharedClient] GET:@"Magazine/All" parameters:@{@"openudid":openUdid} success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
        NSMutableDictionary *result = responseObject[@"data"];
        if([result isKindOfClass:[NSNull class]] || [result count] == 0){
            [SVProgressHUD showErrorWithStatus:@"没有数据"];
            return;
        }
        if (ArraySubTable==nil||ArraySubTable.count==0) {
            ArraySubTable=[[NSMutableArray alloc]initWithArray:responseObject[@"data"]];
        }
        [self MeTableloadNews];
        [self.subTableView reloadData];
        
        [SVProgressHUD dismiss];
        [self.refreshHeaderView egoRefreshScrollViewDataSourceDidFinishedLoading:self.subTableView];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"ERR: %@",operation.responseString);
        
    }];
}
-(void)MeTableloadNews{
    //判断续订
    BOOL islongin=IFUserLogin?YES:NO;
    if (islongin) {
        
    
    NSMutableDictionary*magidDic=[[UserDefaults objectForKey:@"mageid"] mutableCopy];
    if (magidDic==nil) {
        magidDic=[[NSMutableDictionary alloc]init];
    }
    
    NSString*user=[[UserDefaults objectForKey:@"user"] objectForKey:@"userid"];
    NSMutableArray*Marray=[[magidDic objectForKey:user] mutableCopy];
        if (Marray==nil) {
                Marray=[[NSMutableArray alloc]init];
            }
    for (NSDictionary*dic in ArraySubTable) {
       
        if ([dic[@"sub"] integerValue]==1&&islongin) {
            [ArrayMeTableView addObject:dic];
            
            [Marray addObject:dic[@"magid"]];
//            
        }else {
           
            if (magidDic[user]) {
                for (NSString*strid in magidDic[user]) {
                    if ([strid isEqualToString:dic[@"magid"]]) {
                        [ArrayMeTableView addObject:dic];
                    }
                }
            }
            
        }
        
    }

        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        
        for (NSString *number in Marray) {
            
            [dict setObject:number forKey:number];
            
        }
        Marray= [NSMutableArray arrayWithArray:[dict allKeys]];
        [magidDic setObject:Marray forKey:user];
    [UserDefaults setObject:magidDic forKey:@"mageid"];
    }
    [self.meTableView reloadData];
    
    [self.refreshHeaderViewTo egoRefreshScrollViewDataSourceDidFinishedLoading:self.meTableView];
    
}
-(void)initTable{
    
    
//    [[UINavigationBar appearance] setTranslucent:NO];
    ArrayMeTableView=[[NSMutableArray alloc]init];
//    productArray=[[NSMutableArray alloc]init];
    self.subTableView.backgroundColor=UIColorFromRGB(0xf5f5f5);
    self.subTableView.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
    self.subTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.subTableView.tag=1;
    EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, 0)];
    view.delegate = self;
    [self.subTableView addSubview:view];
    self.refreshHeaderView = view;
    self.refreshHeaderView.tag=1;

    
    self.meTableView.backgroundColor=UIColorFromRGB(0xf5f5f5);
    self.meTableView.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
    self.meTableView.separatorStyle=UITableViewCellSeparatorStyleNone;
    self.meTableView.hidden=YES;
    self.meTableView.tag=2;
    EGORefreshTableHeaderView *viewto = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, 0)];
    viewto.delegate = self;
    [self.meTableView addSubview:viewto];
    [self.view insertSubview:self.meTableView atIndex:self.view.subviews.count-1];
    self.refreshHeaderViewTo = viewto;
    self.refreshHeaderViewTo.tag=2;
    
//    self.mallTableview.backgroundColor=UIColorFromRGB(0xf5f5f5);
//    self.mallTableview.tableFooterView=[[UIView alloc]initWithFrame:CGRectZero];
//    self.mallTableview.separatorStyle=UITableViewCellSeparatorStyleNone;
//    self.mallTableview.hidden=YES;
//    self.mallTableview.tag=3;
//    EGORefreshTableHeaderView *viewthr = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0,0, self.view.frame.size.width, 0)];
//    viewto.delegate = self;
//    [self.mallTableview addSubview:viewthr];
//    [self.view insertSubview:self.mallTableview atIndex:self.view.subviews.count-1];
//    self.refreshHeaderViewTo = viewthr;
//    self.refreshHeaderViewTo.tag=3;
    
    
    
    
    
    
    
//    self.segmented=[[UISegmentedControl alloc]initWithItems:@[@"推荐",@"我的"]];
//    self.segmented.frame=CGRectMake(8, 15, self.view.frame.size.width-16, 30);
//    self.segmented.selectedSegmentIndex=0;
//    self.segmented.tintColor=[UIColor redColor];
//    self.segmented.backgroundColor=[UIColor whiteColor];
//    [self.segmented addTarget:self action:@selector(Columns:) forControlEvents:UIControlEventValueChanged];
//    [self.HeadView addSubview:self.segmented];
   
    
}

-(void)viewDidLayoutSubviews{
    self.subTableView.frame=CGRectMake(0, 68, self.view.frame.size.width, self.view.frame.size.height-68);
    self.meTableView.frame=CGRectMake(0, 68, self.view.frame.size.width, self.view.frame.size.height-68);

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(void)Set_segmented:(BOOL)seg{
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    [button setFrame:CGRectMake(0, 0, 22, 22)];
    [button addTarget:self action:@selector(popOfDismss) forControlEvents:UIControlEventTouchUpInside];
    [button setImage:[UIImage imageNamed:@"dismiss"] forState:UIControlStateNormal];
 
    UIBarButtonItem*leftBarItem = [[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.leftBarButtonItem=leftBarItem;
    if (seg) {
        self.segmented.selectedSegmentIndex=1;
        
    }else{
        self.segmented.selectedSegmentIndex=0;
    }
    [self Columns:self.segmented];
}
-(void)popOfDismss{
    if ([[self.navigationController viewControllers] count]>=2) {
        [self.navigationController popViewControllerAnimated:YES];
        
    }else{
        
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}
- (void)Columns:(id)sender {
    UISegmentedControl*se=sender;
    
    if (se.selectedSegmentIndex==0) {
        self.meTableView.hidden=YES;
    }
    if (se.selectedSegmentIndex==1) {
        self.meTableView.hidden=NO;
        [self doneLoadingViewData];
    }
    
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//#warning Potentially incomplete method implementation.
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
//#warning Incomplete method implementation.
    // Return the number of rows in the section.
    if (tableView.tag==1) {
        return ArraySubTable.count;
    }else if (tableView.tag==2){
        return ArrayMeTableView.count;
    }else{
       return 0;
    }
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag==1) {
        return 205;
    }else if (tableView.tag==2){
        return 190;
    }else{
        return 0;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView.tag==1) {
        
    
    SubscriptionCell *cell = [tableView dequeueReusableCellWithIdentifier:@"subcell" forIndexPath:indexPath];
    if (cell==nil) {
        cell=[tableView dequeueReusableCellWithIdentifier:@"subcell"];
        
    }
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        NSDictionary*dic=ArraySubTable[indexPath.row];
        //生成星星
        DPMeterView *fiveStarsShape = (DPMeterView *)[cell.contentView viewWithTag:33];
        [fiveStarsShape setMeterType:DPMeterTypeLinearHorizontal];
        [fiveStarsShape setShape:[UIBezierPath stars:5 shapeInFrame:fiveStarsShape.bounds].CGPath];
        [fiveStarsShape setTrackTintColor:[UIColor lightGrayColor]];
        [fiveStarsShape setProgressTintColor:[UIColor orangeColor]];
        float rate = [dic[@"rate"] intValue];
        [fiveStarsShape setProgress:rate/10 animated:YES];
     
        UIImageView*imageview=(UIImageView*)[cell.contentView viewWithTag:11];
        [imageview sd_setImageWithURL:[NSURL URLWithString:dic[@"image"]]placeholderImage:[UIImage imageNamed:@"icon_default_ipad"]];
        
        UILabel*title=(UILabel*)[cell.contentView viewWithTag:22];
        title.text=dic[@"name"];

        //删除cell重复生成的button
        for (UIButton*view in cell.contentView.subviews) {
            if ([view isKindOfClass:[UIButton class]]) {
//                NSLog(@"%@",view);
                [view removeFromSuperview];
            }
        }
        
        UILabel *subcountLabel = (UILabel*)[cell.contentView viewWithTag:223];
        subcountLabel.text=[NSString stringWithFormat:@"已有%@人订阅",dic[@"subcount"]];
        
        UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
        [button setTag:indexPath.row+1000];
            [button setTitle:@"订阅" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [button setBackgroundColor:UIColorFromRGB(0x8487ba)];
            [button setEnabled:YES];
            [button setTag:indexPath.row*100+5];
            [button addTarget:self action:@selector(pushOrderView:) forControlEvents:UIControlEventTouchUpInside];

        button.layer.cornerRadius = 5;
        button.layer.masksToBounds = YES;
        
        [button setFrame:CGRectMake(135, 110, 45, 30)];
        [cell.contentView addSubview:button];
        
        UIButton*imagebutton=[UIButton buttonWithType:UIButtonTypeCustom];
        [imagebutton setTag:indexPath.row+1000];
        [imagebutton setBackgroundColor:[UIColor clearColor]];
        [imagebutton setTag:indexPath.row*100+5];
        [imagebutton addTarget:self action:@selector(pushOrderView:) forControlEvents:UIControlEventTouchUpInside];
        [imagebutton setFrame:CGRectMake(15, 15, 95, 125)];
        [cell.contentView addSubview:imagebutton];
        
        float size = self.view.frame.size.width/3-5;
        for (long i=0; i<3; i++) {
            UIButton *sbutton = [UIButton buttonWithType:UIButtonTypeCustom];
            [sbutton setFrame:CGRectMake(15+size*i, 165, size-15, 25)];
            [sbutton setFont:[UIFont systemFontOfSize:15]];
            if (i==0) {
                [sbutton setTitle:@"6元/月" forState:UIControlStateNormal];
            }else if (i==1){
                [sbutton setTitle:@"30元/半年" forState:UIControlStateNormal];
            }else{
                [sbutton setTitle:@"50元/年" forState:UIControlStateNormal];
            }
            [sbutton setTag:indexPath.row*100+i];
            sbutton.backgroundColor=UIColorFromRGB(0x8487ba);
            [sbutton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [sbutton setBackgroundImage:nil forState:UIControlStateNormal];
            [sbutton addTarget:self action:@selector(pushOrderView:) forControlEvents:UIControlEventTouchUpInside];
            [cell.contentView addSubview:sbutton];
            
        }

    return cell;
    }else if(tableView.tag==2){
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"mecell" forIndexPath:indexPath];
        if (cell==nil) {
            cell=[tableView dequeueReusableCellWithIdentifier:@"mecell"];
        }
        NSDictionary*dic=ArrayMeTableView[indexPath.row];
        UIImageView*imageview=(UIImageView*)[cell.contentView viewWithTag:11];
        [imageview sd_setImageWithURL:[NSURL URLWithString:dic[@"image"]] placeholderImage:[UIImage imageNamed:@"icon_default_ipad"]];
        UILabel*name=(UILabel*)[cell.contentView viewWithTag:22];
        name.text=dic[@"name"];
        
        DPMeterView *fiveStarsShape = (DPMeterView *)[cell.contentView viewWithTag:233];
        [fiveStarsShape setMeterType:DPMeterTypeLinearHorizontal];
        [fiveStarsShape setShape:[UIBezierPath stars:5 shapeInFrame:fiveStarsShape.bounds].CGPath];
        [fiveStarsShape setTrackTintColor:[UIColor lightGrayColor]];
        [fiveStarsShape setProgressTintColor:[UIColor orangeColor]];
        float rate = [dic[@"rate"] intValue];
        [fiveStarsShape setProgress:rate/10 animated:YES];
        
        UILabel *subcountLabel = (UILabel*)[cell.contentView viewWithTag:33];
        subcountLabel.text=[NSString stringWithFormat:@"已有%@人订阅",dic[@"subcount"]];
        //删除cell重复生成的button
        for (UIButton*view in cell.contentView.subviews) {
            if ([view isKindOfClass:[UIButton class]]) {
                //                NSLog(@"%@",view);
                [view removeFromSuperview];
            }
        }
        UIButton*button=[UIButton buttonWithType:UIButtonTypeCustom];
        
        if ([dic[@"sub"] integerValue]==1&&IFUserLogin) {
            [button setTitle:@"阅读" forState:UIControlStateNormal];
            button.layer.borderWidth = 1;
            button.layer.borderColor = [[UIColor redColor] CGColor];
            [button setBackgroundColor:[UIColor whiteColor]];
            [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
 
            [button setEnabled:NO];
            UILabel*l44=(UILabel*)[cell.contentView viewWithTag:44];
            l44.text=@"有效日期:";
            UILabel*l55=(UILabel*)[cell.contentView viewWithTag:55];
            l55.hidden=NO;
            l55.text=[NSString stringWithFormat:@"%@至%@",dic[@"from"],dic[@"expire"]];
        }else{
            [button setTitle:@"续订" forState:UIControlStateNormal];
            [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
            [button setBackgroundColor:UIColorFromRGB(0x8487ba)];
            [button setEnabled:YES];
            [button setTag:indexPath.row*100+5];
            [button addTarget:self action:@selector(pushOrderView:) forControlEvents:UIControlEventTouchUpInside];
            UILabel*l44=(UILabel*)[cell.contentView viewWithTag:44];
            l44.text=@"尊敬的用户你的订购已过期,请续订";
            UILabel*l55=(UILabel*)[cell.contentView viewWithTag:55];
            l55.hidden=YES;
        }
        button.layer.cornerRadius = 5;
        button.layer.masksToBounds = YES;
        [button setFrame:CGRectMake(135, 110, 45, 30)];
        [cell.contentView addSubview:button];
        return cell;
    }else{
        return nil;
    }
}

-(void)pushOrderView:(id)obj{
    
    UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
    OrderViewController*OrderView=[story instantiateViewControllerWithIdentifier:@"OrderViewController"];
    OrderView.Dict=ArraySubTable[[obj tag]/100];
    OrderView.item=[NSNumber numberWithInt:[obj tag]%100] ;
//    NSLog(@"row___%d  item___%d",[obj tag]/100,[obj tag]%100);
    [self.navigationController pushViewController:OrderView animated:YES];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView.tag==1) {
        
        NSDictionary*dic=ArraySubTable[indexPath.row];
       // SubscriptionCell *cell=(SubscriptionCell *)[tableView cellForRowAtIndexPath:indexPath];
    
        //NSSet *productIdentifiers;
//        switch (cell.Money) {
//            case Sub_One:
                //productIdentifiers= [NSSet setWithObjects:dic[@"itemid"][@"1"],dic[@"itemid"][@"6"],dic[@"itemid"][@"12"],nil];
//                break;
//            case Sub_Six:
//                productIdentifiers= [NSSet setWithObjects:dic[@"itemid"][@"6"],nil];
//                break;
//            case Sub_Twelve:
//                productIdentifiers= [NSSet setWithObjects:dic[@"itemid"][@"12"],nil];
//                break;
//                
//            default:
//                break;
//        }

            //NSLog(@"Product Identifiers:%@",productIdentifiers);
        
//        NSDictionary*dic=ArraySubTable[indexPath.row];
        if ([dic[@"sub"] integerValue]==1) {
            [self performSegueWithIdentifier:@"subPlist" sender:ArraySubTable[indexPath.row][@"magid"]];
        }
    }else{
        NSDictionary*dic=ArrayMeTableView[indexPath.row];
        if ([dic[@"sub"] integerValue]==1) {
            [self performSegueWithIdentifier:@"subPlist" sender:ArrayMeTableView[indexPath.row][@"magid"]];
        }
        
    }
    [tableView deselectRowAtIndexPath:indexPath animated:NO];//点击后不会有阴影
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    UIViewController *destination = segue.destinationViewController;
//    if([destination isKindOfClass:[ArticleViewController class]]){
    [destination setValue:sender forKey:@"magid"];

//    }
}



#pragma mark -
#pragma mark - UIScrollViewDelegate Methods

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView.tag==1) {
        self.reloading = NO;
        [self.refreshHeaderView egoRefreshScrollViewDidScroll:scrollView];
    }else{
       self.reloadingTo = NO;
        [self.refreshHeaderViewTo egoRefreshScrollViewDidScroll:scrollView];
    }
    
    
    
}

- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate{
    if (scrollView.tag==1) {
        [self.refreshHeaderView egoRefreshScrollViewDidEndDragging:scrollView];
    }else{
        [self.refreshHeaderViewTo egoRefreshScrollViewDidEndDragging:scrollView];
    }
    
    
}
#pragma mark RefreshHeaderViewDelegate Methods

-(void)egoRefreshTableHeaderDidTriggerRefresh:(EGORefreshTableHeaderView *)view{
    if (view.tag==1) {
        self.reloading=YES;
    }else{
        self.reloadingTo=YES;
    }
    _page = 1;
    [self performSelector:@selector(doneLoadingViewData) withObject:nil afterDelay:0];
}
- (void)doneLoadingViewData{
    
    //  model should call this when its done loading
    self.reloading = NO;
    self.reloadingTo = NO;
    ArraySubTable = [[NSMutableArray alloc]init];
    ArrayMeTableView = [[NSMutableArray alloc]init];
    [self subTableloadNews];
//    [self mallTableLoadNews];
}
-(BOOL)egoRefreshTableHeaderDataSourceIsLoading:(EGORefreshTableHeaderView *)view{
    if (view.tag==1) {
      return self.reloading;
    }else{
        return self.reloadingTo;
    }
    
}
-(NSDate *)egoRefreshTableHeaderDataSourceLastUpdated:(EGORefreshTableHeaderView *)view{
    return [NSDate date];
}



//新加的方法
//点击订阅及我的订阅按钮的事件效果
- (IBAction)tuiJianButtonEvent:(id)sender {
    [_tuiJianButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [_myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_mallButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.meTableView.hidden=YES;
    myCollectionView.hidden = YES;
    [UIView animateWithDuration:0.3 animations:^(void){_redLineView.frame = CGRectMake(_tuiJianButton.frame.origin.x, _redLineView.frame.origin.y, _redLineView.frame.size.width, _redLineView.frame.size.height);} completion:^(BOOL finished) {
                _redLineView.alpha = 1;
             }];
}

- (IBAction)myButtonEvent:(id)sender {
//    [UserDefaults setObject:@"right" forKey:@"center"];
    
//    if (![UserDefaults objectForKey:@"user"]) {
//        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
//        LoginViewController*login=[story instantiateViewControllerWithIdentifier:@"LoginViewController"];
//        [self.navigationController pushViewController:login animated:YES];
//        return;
//    }
    
    [_tuiJianButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_myButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [_mallButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.meTableView.hidden=NO;
    myCollectionView.hidden=YES;
    [self doneLoadingViewData];
    
    [UIView animateWithDuration:0.3 animations:^(void){_redLineView.frame = CGRectMake(_myButton.frame.origin.x, _redLineView.frame.origin.y, _redLineView.frame.size.width, _redLineView.frame.size.height);} completion:^(BOOL finished) {
        _redLineView.alpha = 1;
    }];

}



- (IBAction)mallButtonEvent:(id)sender {
    
    [myCollectionView reloadData];
    
    
    
    [_mallButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [_tuiJianButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [_myButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    
    myCollectionView.hidden = NO;
    _meTableView.hidden=YES;
    [UIView animateWithDuration:0.3 animations:^(void){_redLineView.frame = CGRectMake(_mallButton.frame.origin.x, _redLineView.frame.origin.y, _redLineView.frame.size.width, _redLineView.frame.size.height);} completion:^(BOOL finished) {
        _redLineView.alpha = 1;
    }];

    
    
}


#pragma mark CollectionView
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return _userData.count + 1 ;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    
    
    NSLog(@"section )=-+_) %ld",(long)section);
    
    if (section == 0) {
        return 1;
    }
    
    else{
        NSMutableDictionary *sectionDic = [[NSMutableDictionary alloc]init];
        sectionDic = _userData [section - 1];//因为加了一行头图，所以数组的section-1
        NSLog(@"_userData )=-+_) %@",_userData);
        
    //    NSLog(@"sectionDic_mall %@",sectionDic);
        if ( [sectionDic count] > 1 ) {
        
            NSMutableArray *sectionAry = [[NSMutableArray alloc]init];
            sectionAry = sectionDic[@"list"];
            NSLog(@"sectionAry %@",sectionAry);
            
            
            
            return sectionAry.count;
 
        }
        
        else{
            return 0;
        }
    }
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"yourCell" forIndexPath:indexPath];
    
    
    //    NSLog(@"cell %@",cell);
    //    UIImageView *recipeImageView = (UIImageView *)[cell viewWithTag:1];
    //    UILabel*label=(UILabel*)[cell viewWithTag:2];
    //    NSLog(@"recipeImageView %@",recipeImageView);
    //    NSLog(@"label %@",label);
    
    //    recipeImageView.image = [UIImage imageNamed:@"121.jpg"];
    //    label.text = @"sb";
    
    NSLog(@"indexPath indexPath %@",indexPath);
    NSLog(@"indexPath indexPath.section %ld",(long)indexPath.section);
    NSLog(@"indexPath indexPath.row %ld",(long)indexPath.row);
    
    
    cell.contentView.layer.borderWidth = 0.5f;
    cell.contentView.layer.borderColor = (__bridge CGColorRef _Nullable)([UIColor blackColor]);
    
    
    if (indexPath.section == 0) {
        [cell.contentView addSubview:Pscroll];
    }
    
    else{
        
        NSMutableDictionary *sectionDic = [[NSMutableDictionary alloc]init];
        sectionDic = _userData [indexPath.section - 1];
        NSLog(@"_userData )=-+_) %@",_userData);
        NSMutableArray *sectionAry = [[NSMutableArray alloc]init];
        NSLog(@"sectionDic_mall %@",sectionDic);
        
        NSMutableDictionary *dataDic = [[NSMutableDictionary alloc]init];
        
        
        
            if ( [sectionDic count] > 1 ) {
                
                
                sectionAry = sectionDic[@"list"];
                NSLog(@"sectionAry %@",sectionAry);
                
                dataDic = sectionAry [indexPath.row];
                
            }
        
        
        UILabel *label = [[UILabel alloc] init];
        label.font = [UIFont systemFontOfSize:18];
        label.textColor = [UIColor blackColor];
    //    label.text = @"男款商务手表";
        //    label.textAlignment = NSTextAlignmentCenter;
        label.text = dataDic[@"name"];
        
        UILabel *moneyLabel = [[UILabel alloc] init];
        moneyLabel.font = [UIFont systemFontOfSize:15];
        moneyLabel.textColor = [UIColor redColor];
    //    moneyLabel.text = @"$888";
        moneyLabel.text = [NSString stringWithFormat:@"￥%@",dataDic[@"discount_price"]] ;
        
        
        NSString *oldPrice = [NSString stringWithFormat:@"￥%@",dataDic[@"price"]] ;
    //    @"¥ 12345";
        
        NSUInteger length = [oldPrice length];
        
        NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:oldPrice];
        [attri addAttribute:NSStrikethroughStyleAttributeName value:@(NSUnderlinePatternSolid | NSUnderlineStyleSingle) range:NSMakeRange(2, length-2)];
        //    [attri addAttribute:NSStrikethroughColorAttributeName value:UIColorFromRGB(0x999999, 1) range:NSMakeRange(2, length-2)];
        [attri addAttribute:NSStrikethroughColorAttributeName value:[UIColor grayColor] range:NSMakeRange(2, length-2)];
        
        
        UILabel *oldMoneyLabel = [[UILabel alloc] init];
        oldMoneyLabel.font = [UIFont systemFontOfSize:15];
        oldMoneyLabel.textColor = [UIColor grayColor];
        //    oldMoneyLabel.text = @"$998";
        [oldMoneyLabel setAttributedText:attri]; //label显示的字体上是否需要加删除线
        
        if ([dataDic[@"discount_price"] isEqualToString:@"0.00"]) {
            moneyLabel.text = [NSString stringWithFormat:@"￥%@",dataDic[@"price"]] ;
            
            oldMoneyLabel.hidden = YES;
        }
        
        UIImageView *imageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon_default_ipad"]];
        [imageView sd_setImageWithURL:[NSURL URLWithString:dataDic[@"pic"][0]] placeholderImage:[UIImage imageNamed:@"icon_default_ipad"]];
         
         
        for (id subView in cell.contentView.subviews) {
            [subView removeFromSuperview];
        }
        
        [cell.contentView addSubview:label];
        [cell.contentView addSubview:imageView];
        [cell.contentView addSubview:moneyLabel];
        [cell.contentView addSubview:oldMoneyLabel];
        
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(cell);
            make.top.equalTo(cell.contentView.mas_top).with.offset(5);
            make.size.mas_equalTo(CGSizeMake(133, 100));
        }];
        
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(cell.contentView.mas_centerX);
            //        make.bottom.equalTo(cell.contentView).with.offset(-10);
            make.top.equalTo(imageView.mas_bottom).with.offset(4);
            make.left.equalTo(imageView.mas_left);
            //        make.right.equalTo(imageView.mas_right);
            make.size.mas_equalTo(CGSizeMake(133, 40));
        }];
        
        [moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(cell.mas_bottom).with.offset(-20);
            make.left.equalTo(imageView.mas_left);
            //        make.right.equalTo(imageView.mas_right);
        }];
        
        [oldMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(cell.mas_bottom).with.offset(-20);
            //        make.left.equalTo(imageView.mas_left);
            make.right.equalTo(imageView.mas_right);
        }];
        
        if(indexPath.section==0)
        {
            cell.backgroundColor = [UIColor whiteColor];
            
            UIView* selectedBGView = [[UIView alloc] initWithFrame:cell.bounds];
            selectedBGView.backgroundColor = [UIColor whiteColor];
            cell.selectedBackgroundView = selectedBGView;
            
        }
        else if(indexPath.section==1)
        {
            
        }
        
        }
    
    cell.backgroundColor = [UIColor whiteColor];
    UIView* selectedBGView = [[UIView alloc] initWithFrame:cell.bounds];
    selectedBGView.backgroundColor = [UIColor whiteColor];
    cell.selectedBackgroundView = selectedBGView;
    
    
    return cell;
}


- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
        if(indexPath.section==0)// && indexPath.row==1
        {
            return CGSizeMake(Pscroll.frame.size.width , Pscroll.frame.size.height);
        }
        else
        {
            return CGSizeMake( acc, 160);
        }
    
    
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    if(section==0)
    {
        //        return UIEdgeInsetsMake(35, 25, 15, 25);
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }
    else
    {
        //        return UIEdgeInsetsMake(15, 15, 15, 15);
        return UIEdgeInsetsMake(0, 0, 0, 0);
    }
}

//各部分的行距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section
{
    if(section==0)
    {
        return 1;
    }
    else
    {
        return 1;
    }
}

//各部分的间距
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
    if(section==0)
    {
        return 1;
    }
    else
    {
        return 1 ;
    }
}



- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    //    [self.myArray removeObjectAtIndex:indexPath.row];
    
    //    [collectionView deleteItemsAtIndexPaths:[NSArray arrayWithObject:indexPath]];
    
    NSLog(@"didSelectItemAtIndexPath indexPath.section %ld",(long)indexPath.section);
    NSLog(@"didSelectItemAtIndexPath indexPath.row %ld",(long)indexPath.row);
    
    self.hidesBottomBarWhenPushed = YES;
    
    if (_userData.count > 0) {
        
    
        NSMutableDictionary *sectionDic = [[NSMutableDictionary alloc]init];
        sectionDic = _userData [indexPath.section - 1];
        NSLog(@"_userData )=-+_) %@",_userData);
        NSMutableArray *sectionAry = [[NSMutableArray alloc]init];
        NSLog(@"sectionDic_mall %@",sectionDic);
        
        NSMutableDictionary *dataDic = [[NSMutableDictionary alloc]init];
        
        
        
        if ( [sectionDic count] > 0 ) {
            
            
            sectionAry = sectionDic[@"list"];
            NSLog(@"sectionAry %@",sectionAry);
            
            dataDic = sectionAry [indexPath.row];
            
            [UserDefaults setObject:dataDic forKey:@"goodsDic"] ;
            
            NSLog(@"set goodsDic %@ ",dataDic);
            
            UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
            AGoodsViewController *opin=[story instantiateViewControllerWithIdentifier:@"AGoodsViewController"];
//            opin.view.backgroundColor=[UIColor colorWithWhite:0.890 alpha:1.000];
            //        [opin opinionInWWW:1];
            [self.navigationController pushViewController:opin animated:YES];
        }
    }
    
    self.hidesBottomBarWhenPushed = NO;
    NSLog(@"正在点击	");
}


//设置分类的名字
- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath

{
    
    UICollectionReusableView *reusableview = nil;
    
//    if (kind == UICollectionElementKindSectionHeader){
//        
//        RecipeCollectionHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
//        
//        NSString *title = [[NSString alloc] initWithFormat:@"Recipe Group #%li",indexPath.section +1];
//        
//        
//        
//        NSLog(@"indexPath.section == %ld",(long)indexPath.section);
//        //当indexPath.section == 0时，是加载头图的时候
//        if (indexPath.section == 0) {
//            
//            headerView.title.text = @"catname";
//            
//            [headerView setFrame:CGRectMake(0, 0, self.view.frame.size.width, 1)];
//            
//            reusableview = headerView;
//            return reusableview;
//        }
//        
//        //然后是加载每一个部分的名字的时候
//        else{
//            
//            NSString *catname = [[NSString alloc]init];
////            NSMutableDictionary *sectionDic = [[NSMutableDictionary alloc]init];
////            sectionDic = _userData [indexPath.section - 1];
////            NSLog(@"sectionDic_mall %@",sectionDic);
////            
////            NSMutableDictionary *dataDic = [[NSMutableDictionary alloc]init];
////
////            
////            
////            if ( [sectionDic count] > 1 ) {
////                
////                
////                catname = sectionDic[@"catname"];
////                
////                NSLog(@"catname %@",catname);
////                
////            }
//            
//            catname = @"sbsbsbbsbsbsbsbbsbsb";
//            headerView.title.text = catname;
//            
//            
//            
//            reusableview = headerView;
//        
//    }
//    
//    }

    
    
    if (kind == UICollectionElementKindSectionFooter){
        
        RecipeCollectionFooterView *footerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath];
        
        NSMutableDictionary *sectionDic = [[NSMutableDictionary alloc]init];
        NSLog(@"indexPath.section == %ld",(long)indexPath.section);
        NSLog(@"_userData _userData _userData _userData _userData %@",_userData);
        footerview.title.text = @"数据加载完毕";
        NSString *catname = [[NSString alloc]init];
        
        if (indexPath.section < _userData.count) {
            
            catname = @"  ";
            if (_userData.count > 0) {
                
                sectionDic = _userData [indexPath.section ];
                NSLog(@"sectionDic_mall %@",sectionDic);
                catname = sectionDic[@"catname"];
            }
            
            
            
            
            
            if ( [sectionDic count] > 1 ) {
                
                
                //                catname = @"sbsbsbbsbsbsbsbbsbsb";
                NSLog(@"catname %@",catname);
            }
            
            
            footerview.title.text = catname;
            
         
        }
        
        else if (indexPath.section == _userData.count){
            footerview.title.text = @"数据加载完毕";
//            footerview.title.textColor = [UIColor lightGrayColor];
//            footerview.title.textAlignment = UITextAlignmentCenter;
        }
        
        reusableview = footerview;
        
    }
    
    reusableview.backgroundColor = [UIColor whiteColor];
    return reusableview;
    
    
    
}


#pragma mark - PageControlScrollViewDelegate

//UIScrollView响应gesture的action
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)gesture
{
    
    
}

-(void)pageScrollDelegate:(PageControlScrollView*)pageScrollView didSelectindex:(int)index{
    
    NSLog(@"index ==- %d",index);
    
    if (topArray.count > 0) {
        self.hidesBottomBarWhenPushed = YES;
        
        NSMutableDictionary *dataDic = topArray [index];

        [UserDefaults setObject:dataDic forKey:@"goodsDic"] ;

        NSLog(@"set goodsDic %@ ",dataDic);

        UIStoryboard*story=[UIStoryboard storyboardWithName:@"Main" bundle:nil];
        AGoodsViewController *opin=[story instantiateViewControllerWithIdentifier:@"AGoodsViewController"];
        //            opin.view.backgroundColor=[UIColor colorWithWhite:0.890 alpha:1.000];
        //        [opin opinionInWWW:1];
        [self.navigationController pushViewController:opin animated:YES];
        
        
        self.hidesBottomBarWhenPushed = NO;
    }

    
    //    topArray.count =  _pageControl.numberOfPages;
}

//点击头图进行跳转界面
-(void)pageScrollDelegate:(PageControlScrollView *)pageScrollView didScrollImageView:(PageImageView*)imageview{
    
    
    
}



@end
